-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Use StringData for Nix language value documentation too
#14527
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
|
🎉 All dependencies have been resolved ! |
| .args = {}, | ||
| .arity = (size_t) arity, | ||
| .doc = doc, | ||
| .doc = &nix::StringData::make(doc), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems to be a reference to a local temporary StringData which promptly becomes a dangling pointer.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is turning a reference into a pointer, and the reference is to a freshly heap-allocated thing, so actually it is fine.
(It errs on the side of leaking without GC, not on the side of the lifetime being too short and getting heap corruption.)
| * Optional free-form documentation about the primop. | ||
| */ | ||
| const char * doc = nullptr; | ||
| const StringData * doc = nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PrimOp is usually not traced, so these StringData would get collected and become a dangling reference.
It could be done by allocating the native primops on the heap or with traceable_allocator.
The C API does allocate them on the GC heap because I needed dynamically allocated ones for NixOps4, but the other, "static" primops will reference garbage.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I made these all be statically allocated StringData with the _sds thing.
| * Optional free-form documentation about the constant. | ||
| */ | ||
| const char * doc = nullptr; | ||
| const StringData * doc = nullptr; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same
| * `null`. | ||
| */ | ||
| const char * doc; | ||
| const StringData & doc; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should probably be similar to the RootValue solution so that Doc can be manipulated as an idiomatic C++ object.
755e3a8 to
110e1d0
Compare
Trailing comma helps a lot.
This probably isn't much of a perf gain, but it does mean we are completely rid of non-length prefixed strings. That allows us to delete some code.
Now that it isn't just used for `Value`, it doesn't really belong in there. Rename `static-string-data.hh` to share the same prefix to keep them close together when sorting lines, also.
110e1d0 to
ddca102
Compare
Motivation
This probably isn't much of a perf gain, but it does mean we are completely rid of non-length prefixed strings. That allows us to delete some code.
Context
Depends on #14442
Add 👍 to pull requests you find important.
The Nix maintainer team uses a GitHub project board to schedule and track reviews.